﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eCompany.Forms
{
    public partial class work_form : Form
    {
        eCompany.eObj.company m_company = null;
        eCompany.eObj.employee m_employee = null;

        public work_form(eCompany.eObj.company company, eCompany.eObj.employee employee)
        {
            m_company = company;
            m_employee = employee;
            InitializeComponent();
            this.Icon = pics.eCompanyIcon;


            this.Text = m_employee.name + " working";
            lblProcuced.Text = "";
            lblcost.Text = "";
            workDateTimePicker.Value = DateTime.Today;
            okCmd.Enabled = false;
        }

        private void productivityMaskedTextBox_TextChanged(object sender, EventArgs e)
        {
            if (productivityMaskedTextBox.Text != "")
            {
                eCompany.eManager.eManager eM = new eManager.eManager();

                int iprod = Convert.ToInt32(productivityMaskedTextBox.Text);

                double units = eCompany.eRules.eCompanyRules.getWorkProducedUnit(m_company, m_employee, iprod);
                lblProcuced.Text = eCompany.eManager.eManager.formatDouble(units) + " units produced";

                double cost = (eM.getEmployeeSalary(m_employee)*8)/units;
                lblcost.Text = eCompany.eManager.eManager.formatDouble(cost) + eM.getAccount(m_company, Guid.Parse(m_company.default_account)).currency+"/unit";
            }
            else
            {
                lblProcuced.Text = "";
                lblcost.Text = "";
            }

            if (productivityMaskedTextBox.Text != "")
                okCmd.Enabled = true;
            else
                okCmd.Enabled = false;
        }

        private void okCmd_Click(object sender, EventArgs e)
        {
            eCompany.eManager.eManager eM = new eManager.eManager();

            int prod = Convert.ToInt32(productivityMaskedTextBox.Text);
            DateTime dt = workDateTimePicker.Value;
            eM.workEmployee(m_company,m_employee,dt,8,prod/*,prod*/);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
    }
}
